<?php
/**
 * An instance of this class is used to generate a stream of
 * pseudorandom numbers. The class uses a 48-bit seed, which is
 * modified using a linear congruential formula. (See Donald Knuth,
 * <i>The Art of Computer Programming, Volume 3</i>, Section 3.2.1.)
 * <p>
 * If two instances of {@code Random} are created with the same
 * seed, and the same sequence of method calls is made for each, they
 * will generate and return identical sequences of numbers. In order to
 * guarantee this property, particular algorithms are specified for the
 * class {@code Random}. Java implementations must use all the algorithms
 * shown here for the class {@code Random}, for the sake of absolute
 * portability of Java code. However, subclasses of class {@code Random}
 * are permitted to use other algorithms, so long as they adhere to the
 * general contracts for all the methods.
 * <p>
 * The algorithms implemented by class {@code Random} use a
 * {@code protected} utility method that on each invocation can supply
 * up to 32 pseudorandomly generated bits.
 * <p>
 * Many applications will find the method {@link Math#random} simpler to use.
 *
 * @author  Frank Yellin
 * @version %I%, %G%
 * @since   1.0
 */
class CMyRandom {

	public function getRandomNumber($md5Keyword,$count){
		$md5Keyword = md5($md5Keyword);
		$value = '';
		for($j=0,$len=strlen($md5Keyword);$j<$len;$j++){
			$value.=ord($md5Keyword[$j]);
		}
		$value = substr($value,0,9);
		$rid=intval($value)%$count;
		return $rid;
	}
	
	public function getRandomNumberMinMax($md5Keyword,$min,$max){
		$md5Keyword = md5($md5Keyword);
		$value = '';
		for($j=0,$len=strlen($md5Keyword);$j<$len;$j++){
			$value.=ord($md5Keyword[$j]);
		}
		$value = substr($value,0,9);
		$rid=intval($value)%($max-$min)+$min;
		return $rid;
	}

}
